<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->

<table class="gio-table-light gio-form-listeners__table" [formGroup]="mainForm">
  <thead>
    <tr>
      <th class="gio-form-listeners__table__row__th">
        <div class="gio-form-listeners__table__title">
          Context-path
          <mat-icon
            class="gio-form-listeners__table__title__icon"
            matTooltip="The URL location of your API. So if your URL is [{{ contextPathPrefix }}/myAPI] then [/myAPI] is the context path."
            svgIcon="gio:info"
          ></mat-icon>
        </div>
        <div class="gio-form-listeners__table__subtitle">
          Must start with a '/' and can contain an uppercase letter, number, dash or underscore.
        </div>
      </th>
      <th class="gio-form-listeners__table__row__th"></th>
    </tr>
  </thead>
  <tbody formArrayName="listeners">
    <tr
      *ngFor="let control of listenerFormArray.controls; index as controlIndex"
      [formGroupName]="controlIndex"
      class="gio-form-listeners__table__row"
    >
      <td class="gio-form-listeners__table__row__td">
        <mat-form-field class="gio-form-listeners__table__field">
          <input type="text" matInput formControlName="path" placeholder="Context-path *" />
          <mat-error *ngIf="control.get('path').hasError('contextPath')"> {{ control.get('path').getError('contextPath') }}</mat-error>
          <mat-error *ngIf="control.get('path').hasError('listeners')"> {{ control.get('path').getError('listeners') }}</mat-error>
        </mat-form-field>
      </td>
      <td class="gio-form-listeners__table__row__td">
        <button
          type="button"
          mat-icon-button
          aria-label="Delete"
          [class.gio-form-listeners__table__row__td__button__hide]="listenerFormArray.controls.length <= 1"
          *ngIf="!isDisabled"
          (click)="onDelete(controlIndex)"
        >
          <mat-icon svgIcon="gio:cancel"></mat-icon>
        </button>
      </td>
    </tr>
  </tbody>
</table>
<span class="mat-error" *ngIf="listenerFormArray.hasError('contextPath')">{{ listenerFormArray.getError('contextPath') }}</span>

<button *ngIf="!isDisabled" class="gio-form-listeners__add-button" type="button" mat-stroked-button (click)="addEmptyListener()">
  Add context-path
</button>
